package com.google.sydym6.view.fragments;

import com.google.sydym6.R;
import com.google.sydym6.controllers.ISongListController;
import com.google.sydym6.controllers.SongListController;
import com.google.sydym6.view.activities.SongInfoActivity;
import com.google.sydym6.view.adapters.SongListAdapter;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class HistoryPageFragment extends Fragment {
	  
	static final String ARGUMENT_RADIO_ID = "arg_rad_id";
	  
	  int backColor;
	  ISongListController controller;
	  SongListAdapter adapter;
  
	  public static HistoryPageFragment newInstance() {
		  HistoryPageFragment pageFragment = new HistoryPageFragment();
		  Bundle arguments = new Bundle();
		  pageFragment.setArguments(arguments);
		  return pageFragment;
	  }
  
	  @Override
	  public void onCreate(Bundle savedInstanceState) {
		  super.onCreate(savedInstanceState);

		  controller = new SongListController(this);
		  adapter = new SongListAdapter(this.getActivity(), R.layout.song_list_item, controller.getList(), controller);
		  backColor = Color.argb(255, 255, 255, 255);
	  }
  
	  @Override
	  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		  View view = inflater.inflate(R.layout.history_fragment, null);
		  
		  view.setBackgroundColor(backColor);
		  
		  ListView songHLV = (ListView) view.findViewById(R.id.songHistoryList);
		  songHLV.setAdapter(adapter);
		  
		  final Activity thisActivity = this.getActivity();
		  
		  songHLV.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
				Intent intent = new Intent(thisActivity, SongInfoActivity.class);
				startActivity(intent);
			}
		  });
		  return view;
	  }
	  
	  @Override
	  public void onDestroy() {
		  super.onDestroy();
		  adapter.release();
		  Log.v("SongPlayer", "HistoryPageFragment onDestroy()");
	  }
}
